var Head = Window02.extend({
	status:false,
	string:"",
	ctor:function (parent, flow, tag) {
		this._super(parent, flow, tag);
	},
	initSp:function (){
		this.background = new cc.Sprite("#head/background.png");
		this.background.setPosition(gg.c_p);
		this.rootNode.addChild(this.background, 5);
		var d_z_index = 10;
		// 显示屏
		var b_screen = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_SCREEN,
				"#head/screen_close.png",
				this.eventMenuCallback,this);
		b_screen.setPosition(320, gg.height * 0.5);
		b_screen.setCascadeOpacityEnabled(true);
		
		var b_7 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_7,
				"#head/7.png",
				this.eventMenuCallback,this);
		b_7.setPosition(320 + b_screen.width * 0.5 + b_7.width * 0.5 + 10, 390);
		var b_8 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_8,
				"#head/8.png",
				this.eventMenuCallback,this);
		b_8.right(b_7);
		var b_9 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_9,
				"#head/9.png",
				this.eventMenuCallback,this);
		b_9.right(b_8);
		
		var b_4 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_4,
				"#head/4.png",
				this.eventMenuCallback,this);
		b_4.down(b_7);
		var b_5 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_5,
				"#head/5.png",
				this.eventMenuCallback,this);
		b_5.right(b_4);
		var b_6 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_6,
				"#head/6.png",
				this.eventMenuCallback,this);
		b_6.right(b_5);
		
		var b_1 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_1,
				"#head/1.png",
				this.eventMenuCallback,this);
		b_1.down(b_4);
		var b_2 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_2,
				"#head/2.png",
				this.eventMenuCallback,this);
		b_2.right(b_1);
		var b_3 = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_3,
				"#head/3.png",
				this.eventMenuCallback,this);
		b_3.right(b_2);
		
		var b_0 = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_0,
				"#head/0.png",
				this.eventMenuCallback,this);
		b_0.down(b_1);
		
		var b_back = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_BACK,
				"#head/back.png",
				this.eventMenuCallback,this);
		b_back.right(b_0, 25);
		
		// 摄像
		var b_camera = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_CAMERA,
				"#head/camera.png",
				this.eventMenuCallback,this);
		b_camera.right(b_back, 70);
		// 风扇
		var b_fan = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_FAN,
				"#head/fan.png",
				this.eventMenuCallback,this);
		b_fan.right(b_camera);
		// 旋转
		var b_rotation = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_ROTATION,
				"#head/rotation.png",
				this.eventMenuCallback,this);
		b_rotation.right(b_fan);
		// 门锁
		var b_lock = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_LOCK,
				"#head/lock.png",
				this.eventMenuCallback,this);
		b_lock.right(b_rotation);
		
		var b_start = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_START,
				"#head/start.png",
				this.eventMenuCallback,this);
		b_start.setPosition(710, 320);
		var b_stop = new Button(this.rootNode, 
				d_z_index, TAG_BUTTON_STOP,
				"#head/stop.png",
				this.eventMenuCallback,this);
		b_stop.setPosition(800, 320);
		
		var ok_X = 710;
		var ok_Y = 430;
		var b_ok = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_OK,
				"#head/ok.png",
				this.eventMenuCallback,this);
		b_ok.setPosition(ok_X, ok_Y);
		var b_left = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_LEFT,
				"#head/left.png",
				this.eventMenuCallback,this);
		b_left.setPosition(ok_X - b_left.width * 0.5 - b_ok.width * 0.5, ok_Y);
		var b_up = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_UP,
				"#head/up.png",
				this.eventMenuCallback,this);
		b_up.setPosition(ok_X,ok_Y + b_up.height * 0.5 + b_ok.width * 0.5);
		var b_right = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_RIGHT,
				"#head/right.png",
				this.eventMenuCallback,this);
		b_right.setPosition(ok_X + b_right.width * 0.5 + b_ok.width * 0.5, ok_Y);
		var b_down = new Button(this.rootNode,
				d_z_index, TAG_BUTTON_DOWN,
				"#head/down.png",
				this.eventMenuCallback,this);
		b_down.setPosition(ok_X,ok_Y - b_up.height * 0.5 - b_ok.width * 0.5);
	},
	start:function(){
		var screen = this.byTag(TAG_BUTTON_SCREEN);
		screen.setSpriteFrame("head/screen_open.png");
		
		this.string = "请用数字键选择：\n[1]建立方案并运行\n[2]调用方案并运行,\n[3]编辑方案\n[4]系统设置";
		this.show = new cc.LabelTTF(this.string,gg.fontName,16);
		this.show.setAnchorPoint(0,1);
		this.show.setColor(cc.color(39,36,179,255));
		this.show.setPosition(10, 130);
		screen.addChild(this.show);
	},
	say:function(){
		this.show.setString(this.string);
	},
	refreshResult:function(){
		this.string = "1--0520W--"+this.curDegree+"°C--20.0atm--03:00\n";
		this.string += "0000W  017°C--00.0atm  00.00\n";
		this.string += "状态:准备    0017 00.0    00:00\n";
		this.string += "----------------------------------\n";
		this.string += "   °C                         atm\n";
		this.string += "150-|                           |-30\n";
		this.string += "100-|                           |-20\n";
		this.string += "050-|                           |-10\n";
		this.string += "000-|-----------------------------00\n";
		this.string += "    0 3 6 9 12 15 18 21 24 27 30";
		this.curDegree --;
		this.say();
	},
	callbackSp:function(pSender){
		var next = true;
		cc.log("say:" + pSender.getTag());
		var action = gg.flow.flow.action;
		switch (pSender.getTag()){
		case TAG_BUTTON_7:
			this.string += "7";
			break;
		case TAG_BUTTON_8:
			this.string += "8";
			break;
		case TAG_BUTTON_9:
			this.string += "9";
			break;
		case TAG_BUTTON_4:
			this.string += "4";
			break;
		case TAG_BUTTON_5:
			this.string += "5";
			break;
		case TAG_BUTTON_6:
			this.string += "6";
			break;
		case TAG_BUTTON_3:
			this.string += "3";
			break;
		case TAG_BUTTON_2:
			this.string += "2";
			break;
		case TAG_BUTTON_1:
			if(!this.status){
				if(gg.flow.flow.status){
					this.status = true;	
					this.string = "步骤  罐数  温度  压力  保持\n";
					this.string += "<N=2> <>=2> <°C> <atm> <m:s>\n";
					this.string += "  1     ";
				} else{
					this.string = "请用数字键选择：\n[1]用户方案\n[2]屹尧方案";
				}
				this.say();
			} else {
				this.string += "1";
			}
			break;
		case TAG_BUTTON_0:
			this.string += "0";
			break;
		case TAG_BUTTON_BACK:	
			break;
		case TAG_BUTTON_LEFT:	
			break;
		case TAG_BUTTON_UP:	
			break;
		case TAG_BUTTON_RIGHT:
			if(action == "space"){
				this.string += "   ";	
			} else if(action == "enter"){
				this.string += gg.flow.flow.str;
			}
			break;
		case TAG_BUTTON_DOWN:
			break;
		case TAG_BUTTON_OK:
			this.curDegree = 150;
			this.refreshResult();
			this.show.setFontSize(12);
			break;
		case TAG_BUTTON_START:	
			// 开始微波
			this.status = true;
			this.layer.clock.doTime(4, 0);
			this.layer.clock.loadTip("#tool/tip5.png");
			this.layer.clock.doing();
			pSender.scheduleOnce(
				function(){
					this.step++;
					this.say();
				}.bind(this),4);
			pSender.schedule(function(){
				this.refreshResult();
			}.bind(this), 0.05, 70);
			this.show.setLocalZOrder(100);
			break;
		case TAG_BUTTON_STOP:
			break;
		case TAG_BUTTON_CAMERA:
			break;
		case TAG_BUTTON_FAN:
			break;
		case TAG_BUTTON_ROTATION:
			var hide_tag = gg.flow.flow.hide_tag
			if(hide_tag != null){
				var hide = this.layer.getChildByTag(hide_tag);
				hide.setVisible(false);
			}
			if(action == ACTION_ROLL){
				this.layer.bodySprite.roll2();
// this.layer.clock.doing();
				pSender.scheduleOnce(
						function(){
// this.layer.clock.stop();
							this.layer.bodySprite.rollStop2();
							gg.flow.next();
						}.bind(this),3);
				var st = new ShowTip();
				st.init("观察炉腔内转盘转动\n应360度往返转动转盘\n不出现绕线情况",3);
				st.setPosition(400, 180);
			} else if(action == ACTION_ROLL_STOP){
				this.layer.bodySprite.rollStop();
			}else if(action == ACTION_ROLL2){
				this.layer.bodySprite.roll();
				pSender.scheduleOnce(
						function(){							
							this.layer.bodySprite.rollStop();
							gg.flow.next();
						}.bind(this),3);
				var st = new ShowTip();
				st.init("观察炉腔内转盘转动\n应360度往返转动转盘\n不出现绕线情况",3);
				st.setPosition(400, 180);
			}
			break;
		case TAG_BUTTON_LOCK:
			ll.run.bodySprite.openDoor();
			if(action == ACTION_DO1){
				var stand = ll.run.getChildByTag(TAG_ITEM_TANK_STAND);
				stand.setVisible(true);
				stand.setOpacity(0);
				stand.runAction(cc.fadeIn(0.5));
			} else if(action == ACTION_DO2){
				var ctrl = ll.run.getChildByTag(TAG_ITEM_TANK_CTRL);
				ctrl.setVisible(true);
				ctrl.setOpacity(0);
				ctrl.runAction(cc.fadeIn(0.5));
			}
			this.step=1;
			break;
		default:
			break;
		}
		if(next){
			gg.flow.next();	
		}
		if(this.status){
			this.say();
		}
	}
})